package com.foreknow.demo3;

import java.util.Scanner;

public class Tect {


        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            String answer = "";
            boolean isRegister = false; //标识是否注册
            String username = "";
            String password = "";

            do {
                System.out.println("*****************欢迎进入*******************");
                System.out.println("1. 注册");
                System.out.println("2. 登录");
                System.out.println("3. 抽奖");
                System.out.println("*****************欢迎进入*******************");

                System.out.println("请输入菜单: ");
                int choice = input.nextInt();
                switch (choice) {
                    case 1:
                        System.out.println("注册");
                        System.out.println("请输入用户名");
                        username = input.next();
                        System.out.println("请输入密码");
                        password = input.next();
                        //生成一个四位的随机数
                        int cardNumber = (int) (Math.random()*(9999-1000))+1000;
                        System.out.println(username+"----"+password+"----"+cardNumber);
                        isRegister = true;
                        break;
                    case 2:
                        System.out.println("登录");
                        if(isRegister){
                            //进行登录
                            for(int i = 1;i<=3;i++) {
                                System.out.println("请输入登录的用户名： ");
                                String inputName = input.next();
                                System.out.println("请输入登录的密码： ");
                                String inputPass = input.next();
                                if(inputName.equals(username)&&inputPass.equals(password)) {
                                    System.out.println("欢迎您"+username);
                                    break;
                                }else if(i < 3) {
                                    System.out.println("您还有" + (3-i) + "次机会");
                                }else {
                                    System.out.println("sorry 您输入的信息不正确 3次错误");
                                }
                            }
                        }else {
                            //请先注册然后才能登录
                            System.out.println("请先注册然后才能登录");
                        }
                        break;
                    case 3:
                        System.out.println("抽奖");
                        break;
                }
                System.out.println("是否继续(y/n)");
                answer = input.next();
            }while(answer.equals("y")); //注意：两个字符串比较一定要使用equals

//        if(answer.equals("n")) {
//            System.out.println("退出系统");
//        }
        }

    }


